package wsn.node;

//import inet.base.NotificationBoard;
import inet.battery.IBattery;
import inet.linklayer.IWirelessNic;
import inet.mobility.IMobility;
import inet.networklayer.common.InterfaceTable;
import inet.networklayer.ipv4.RoutingTable;
import wsn.linklayer.idealwireless.CC1000IdealWirelessNic;
import wsn.networklayer.WSNNetworkLayer;
import inet.base.NotificationBoard;

module NodeBase
{
    parameters:
        @display("bgb=,448");
        @node;
        @labels(node,wireless-node);
        bool isBaseStation = default(false);
        bool IPForward = default(false);
        bool forwardMulticast = default(false);
        int numRadios = default(1);
        string mobilityType = default(numRadios > 0 ? "StationaryMobility" : "");
        string routingFile = default("");
        string batteryType = default("WSNSimpleBattery");
    gates:
        input radioIn[numRadios] @directIn;
    submodules:
        notificationBoard: NotificationBoard {
            parameters:
                @display("p=53,155;is=s");
        }

        battery: <batteryType> like IBattery if batteryType != "" {
            parameters:
                @display("p=53,77;i=block/plug;is=s");
        }

        // optional mobility module. Required only if wireless cards are present
        mobility: <mobilityType> like IMobility if mobilityType != "" {
            parameters:
                @display("p=53,111");
        }

        // network layer
        networkLayer: WSNNetworkLayer {
            parameters:
                @display("p=216,287;q=queue");
                isBaseStation = isBaseStation;
        }

        routingTable: RoutingTable {
            parameters:
                @display("p=53,225;is=s");
                IPForward = IPForward;
                forwardMulticast = forwardMulticast;
                routingFile = routingFile;
        }

        // linklayer
        interfaceTable: InterfaceTable {
            parameters:
                @display("p=53,287;is=s");
        }
        
        wlan[numRadios]: <default("CC1000IdealWirelessNic")> like IWirelessNic {
            parameters:
                @display("p=216,406,row,60;q=queue");
        }

    connections allowunconnected:
        // connections to network outside
        for i=0..sizeof(radioIn)-1 {
            radioIn[i] --> { @display("m=s"); } --> wlan[i].radioIn;
            wlan[i].upperLayerOut --> networkLayer.ifIn++;
            wlan[i].upperLayerIn <-- networkLayer.ifOut++;
        }

}